package org.brazilo.movi.miaamiko;

import org.brazilo.movi.miaamiko.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Handler;

public class StandardDialog {
	public static final int dlgResultOk         = 1;
	public static final int dlgResultYes        = 2;
	public static final int dlgResultNo         = 3;
	public static final int dlgResultCancel     = 4;
	
	public static final int dlgTypeOk           = 10;
	public static final int dlgTypeYesNo        = 11;
	public static final int dlgTypeYesNoCancel  = 12;
	public static final int dlgTypeAbout  = 13;
	
	private Handler mResponseHandler;
	private AlertDialog.Builder mDialogBuilder;
	private int mDialogId;
	
	public StandardDialog(Activity parent, Handler reponseHandler, String title, String message, int dialogType, int dialogId) {
	    mResponseHandler = reponseHandler;
	    mDialogId = dialogId;
	    mDialogBuilder = new AlertDialog.Builder(parent);
	    mDialogBuilder.setCancelable(false);
	    mDialogBuilder.setTitle(title);
	    mDialogBuilder.setIcon(android.R.drawable.ic_dialog_alert);
	    mDialogBuilder.setMessage(message);
	    switch (dialogType) {
		    case dlgTypeOk:
		        mDialogBuilder.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
		            @Override
					public void onClick(DialogInterface dialog, int which) {
		                mResponseHandler.sendEmptyMessage(mDialogId + dlgResultOk);
		            }
		        });
		        break;
		    case dlgTypeAbout:
		    	mDialogBuilder.setTitle("Mia Amiko Androjdo v2.0");
	        	mDialogBuilder.setIcon(R.drawable.ic_launcher);
	    	    mDialogBuilder.setMessage("Projeto MOVI\nhttp://movi.brazilo.org\n\nAprenda Esperanto\nhttp://miaamiko.brazilo.org");
	    	    mDialogBuilder.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
		            @Override
					public void onClick(DialogInterface dialog, int which) {
		                mResponseHandler.sendEmptyMessage(mDialogId + dlgResultOk);
		            }
		        });
		        break;		    		
		    case dlgTypeYesNo:
		    case dlgTypeYesNoCancel:
		        mDialogBuilder.setPositiveButton("Sim", new DialogInterface.OnClickListener() {
		            @Override
					public void onClick(DialogInterface dialog, int which) {
		                mResponseHandler.sendEmptyMessage(mDialogId + dlgResultYes);
		            }
		        });         
		        mDialogBuilder.setNegativeButton("Não", new DialogInterface.OnClickListener() {
		            @Override
					public void onClick(DialogInterface dialog, int which) {
		                mResponseHandler.sendEmptyMessage(mDialogId + dlgResultNo);
		            }
		        });         
		        if (dialogType == dlgTypeYesNoCancel) {
		            mDialogBuilder.setNeutralButton("Cancelar", new DialogInterface.OnClickListener() {
		                @Override
						public void onClick(DialogInterface dialog, int which) {
		                    mResponseHandler.sendEmptyMessage(mDialogId + dlgResultCancel);
		                }
		            });         
		        }
		        break;
		    }
		    mDialogBuilder.show();
	}
}